package com.personal.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.personal.mapper.TClassroomMapper;
import com.personal.mapper.TCoachMapper;
import com.personal.mapper.TCourseMapper;
import com.personal.mapper.TReserveMapper;
import com.personal.pojo.TClassroomExample;
import com.personal.pojo.TCoach;
import com.personal.pojo.TCoachExample;
import com.personal.service.CoachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CoachServiceImp implements CoachService {
    @Autowired
    private TCoachMapper coachMapper;
    @Autowired
    private TCourseMapper courseMapper;
    @Autowired
    private TClassroomMapper classroomMapper;
    @Autowired
    private TReserveMapper reserveMapper;

    //1.教练登录
    @Override
    public TCoach login(String logname, String password) {
        return coachMapper.selectByNamePass(logname,password);
    }


    @Override
    public int editOneself(TCoach coach) {
        return coachMapper.updateByPrimaryKeySelective(coach);
    }

    @Override
    public TCoach findBycoachId(Integer coachid) {
        return coachMapper.selectByPrimaryKey(coachid);
    }

    //查询状态为非结束的所有课程
    @Override
    public PageInfo findNotEnd(int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List list = courseMapper.selectNotEnd();
        PageInfo info = new PageInfo(list);
        return info;
    }

    //多条件查询，教练功能，查未结束的课程
    @Override
    public PageInfo findByTimeName(int pageNum,int pageSize,Integer weekid, Integer sectionid, String coursename) {
        PageHelper.startPage(pageNum,pageSize);
        List list = courseMapper.selectByTimeName(weekid,sectionid,coursename);
        PageInfo info = new PageInfo(list);
        return info;
    }

    //根据coachid查询课程，形成教练的课程表
    @Override
    public List findByCoachid(Integer coachid) {
        return courseMapper.selectByCoachid(coachid);
    }

    @Override
    public PageInfo findClassroom(int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List list = classroomMapper.selectByExample();
        PageInfo info = new PageInfo(list);
        return info;
    }

    @Override
    public int deleteMem(Integer reserveid) {
        return reserveMapper.deleteByPrimaryKey(reserveid);
    }

    @Override
    public PageInfo findByCluase(int pageNum,int pageSize,String classroomtype, Integer min, Integer max, String classroomName) {
        PageHelper.startPage(pageNum,pageSize);
        List list = classroomMapper.selectByCluase(classroomtype,min,max,classroomName);
        PageInfo info = new PageInfo(list);
        return info;
    }

    @Override
    public List findAllMem(Integer coachid) {
        return reserveMapper.selectAllMem(coachid);
    }
}
